package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目有关接口")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("分页查询护理项目")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(String name,
                                                                    @RequestParam(defaultValue = "1" )Integer pageNum,
                                                                    @RequestParam(defaultValue = "10")Integer pageSize,
                                                                    Integer status){

        PageResponse<NursingProjectVo> response =nursingProjectService.getByPage(name,pageNum,pageSize,status);
        return ResponseResult.success(response);
    }

    @PostMapping
    @ApiOperation("护理项目新增操作")
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.add(nursingProjectDto);
        return  ResponseResult.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("护理项目根据ID获取信息操作")
    public ResponseResult getById(@PathVariable Long id){
        NursingProjectVo nursingProjectVo=nursingProjectService.getById(id);
        return ResponseResult.success(nursingProjectVo);
    }

    @PutMapping
    @ApiOperation("护理项目更新操作")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){

        nursingProjectService.update(nursingProjectDto);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("护理项目状态更新操作")
    public  ResponseResult updateStatus(@PathVariable Long id,@PathVariable Integer status){
        nursingProjectService.updateStatus(id,status);
        return ResponseResult.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("护理项目删除操作")
    public ResponseResult deleteById(@PathVariable Long id){
        nursingProjectService.deleteById(id);
        return  ResponseResult.success();
    }

    @GetMapping("/all")
    @ApiOperation("护理项目查询所有操作")
    public ResponseResult<List<NursingProjectVo>> get(){
        List<NursingProjectVo> list=nursingProjectService.get();
        return ResponseResult.success(list);
    }
}
